package Veterinaria.servlets;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Veterinaria.excepcion.DAOExcepcion;
import Veterinaria.modelo.Cita;
import Veterinaria.negocio.GestionCita;

/**
 * Servlet implementation class ReporteCitasSerlvet
 */
@WebServlet("/ReporteCitasSerlvet")
public class ReporteCitasSerlvet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ReporteCitasSerlvet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String paciente = request.getParameter("txtPaciente");
		String tcita = request.getParameter("select");
		String desde =  request.getParameter("txtDesde");
		String hasta = request.getParameter("txtHasta");
		String estado = request.getParameter("select2");
		
		GestionCita cita = new GestionCita();
		try {
			Collection<Cita> o = cita.obtenerReporteCita(paciente, tcita, desde, hasta, estado);
			Collection<Cita> lista = new ArrayList<Cita>();
			lista.addAll(o);
			// Guardar en el ambiente de request
			request.setAttribute("citas", lista);
			RequestDispatcher rd = request
					.getRequestDispatcher("reporte_cita.jsp");
			rd.forward(request, response);

		} catch (DAOExcepcion e) {
			System.out.println(e.getMessage());
			//RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			//rd.forward(request, response);
		}
	}

}
